package com.hrs.util;

import com.hrs.common.constant.RequestUserData;

import java.util.Objects;

/**
 * @author 摆渡人
 * @description
 * @date 2022/12/6 9:55
 */
public class RequestUserUtil {

    private static final String USER_KEY = "smart_admin_user";

    private static ThreadLocal<RequestUserData> requestUserThreadLocal = new ThreadLocal<RequestUserData>();

    public static void setUser(RequestUserData requestUserData) {
        requestUserThreadLocal.set(requestUserData);
    }

    public static RequestUserData getThreadLocalUser() {
        return requestUserThreadLocal.get();
    }

    public static Long getRequestUserId() {
        RequestUserData threadLocalUser = getThreadLocalUser();
        if (Objects.isNull(threadLocalUser)) {
            return null;
        }
        return threadLocalUser.getId();
    }

    public static void removeUser(){
        requestUserThreadLocal.remove();
    }

}
